﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Zocono.Infrastructure.Common;
using Zocono.WCS.Application.AppConfigureManage;
using Zocono.WCS.Infrastructure.ApllicationDto.DtoWcsManage;

namespace Zocono.WCS.WebApi.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class PlanarProcessServiceMapController : ControllerBase
    {
        private readonly ILogUtil _logger;
        private readonly PlanarProcessServiceMapApp _planarProcessServiceMapApp;
        public PlanarProcessServiceMapController(ILogUtil logger, PlanarProcessServiceMapApp planarProcessServiceMapApp)
        {
            _logger = logger;
            _planarProcessServiceMapApp = planarProcessServiceMapApp;
        }

        [HttpPost]
        public async Task<HeaderResult<long>> AddPlanarProcessServiceMapAsync(PlanarProcessServiceMapInfoDto PlanarProcessServiceMapInfoDto)
        {
            try
            {
                long result = await _planarProcessServiceMapApp.AddPlanarProcessServiceMapAsync(PlanarProcessServiceMapInfoDto);
                return ApiBase.Success(result, "新增平面设备报文业务配置成功");
            }
            catch (Exception ex)
            {
                _logger.Error(ex.ToString());
                return ApiBase.Error<long>(ex.Message);
            }
        }

        [HttpGet]
        public async Task<HeaderResult<bool>> DeletePlanarProcessServiceMapAsync(long ID)
        {
            try
            {
                bool result = await _planarProcessServiceMapApp.DeletePlanarProcessServiceMapAsync(ID);
                return ApiBase.Success<bool>("删除平面设备报文业务配置成功");
            }
            catch (Exception ex)
            {
                _logger.Error(ex.ToString());
                return ApiBase.Error<bool>(ex.Message);
            }
        }

        [HttpPost]
        public async Task<HeaderResult<bool>> UpdatePlanarProcessServiceMapAsync(PlanarProcessServiceMapInfoDto PlanarProcessServiceMapInfoDto)
        {
            try
            {
                bool result = await _planarProcessServiceMapApp.UpdatePlanarProcessServiceMapAsync(PlanarProcessServiceMapInfoDto);
                return ApiBase.Success<bool>("修改平面设备报文业务配置成功");
            }
            catch (Exception ex)
            {
                _logger.Error(ex.ToString());
                return ApiBase.Error<bool>(ex.Message);
            }
        }

        [HttpPost]
        public async Task<HeaderResult<List<PlanarProcessServiceMapInfoDto>>> GetAllPlanarProcessServiceMapAsync(QueryPlanarProcessServiceMapInfoDto queryPlanarProcessServiceMapDto)
        {
            try
            {
                var list = await _planarProcessServiceMapApp.GetPlanarProcessServiceMapAsync(queryPlanarProcessServiceMapDto);
                return ApiBase.Success(list, "查询成功");
            }
            catch (Exception ex)
            {
                _logger.Error(ex.ToString());
                return ApiBase.Error<List<PlanarProcessServiceMapInfoDto>>(ex.Message);
            }
        }

        [HttpGet]
        public async Task<HeaderResult<PlanarProcessServiceMapInfoDto>> GetPlanarProcessServiceMapByIDAsync(long ID)
        {
            try
            {
                var result = await _planarProcessServiceMapApp.GetPlanarProcessServiceMapByIDAsync(ID);
                return ApiBase.Success(result, "获取数据成功");
            }
            catch (Exception ex)
            {
                _logger.Error(ex.ToString());
                return ApiBase.Error<PlanarProcessServiceMapInfoDto>(ex.Message);
            }
        }
    }
}
